Skip to content

fix(sdk): support async generator functions in control() decorator#116

Open
KazChe wants to merge 1 commit intoagentcontrol:mainfrom
KazChe:fix/async-generator-control-decorator
Open

fix(sdk): support async generator functions in control() decorator#116
KazChe wants to merge 1 commit intoagentcontrol:mainfrom
KazChe:fix/async-generator-control-decorator

Conversation

@KazChe
Copy link

@KazChe KazChe commented Mar 12, 2026

Summary

  • adds async generator (streaming) support to the control() decorator, fixing crashes and silent bypasses when applied to async def functions with yield — the standard pattern for LLM response streaming.

Scope

  • User-facing/API changes: @control() now correctly wraps async generator functions, preserving inspect.isasyncgenfunction() identity
  • Internal changes: New async_gen_wrapper path in control() that runs pre-check before first chunk, yields chunks in real-time while accumulating, and runs post-check on full accumulated output after stream completes
  • Out of scope: Sync generator support, per-chunk evaluation

Risk and Rollout

  • Risk level: low
  • Rollback plan: Revert commit — the change is additive (new code path) with no modifications to existing sync/async wrapper logic

Testing

  • Added or updated automated tests
  • Ran make check (lint + typecheck pass; server tests have pre-existing postgres failures unrelated to this change)
  • Manually verified behavior

Checklist

The control() decorator silently broke on streaming (async generator)
functions — the standard pattern for LLM response streaming.This adds
an async_gen_wrapper path that runs pre-check before the first chunk,
yields chunks in real-time while accumulating output, and runs
post-check on the full accumulated output after the stream completes.
fixes agentcontrol#113
@abhinav-galileo abhinav-galileo self-requested a review March 12, 2026 14:43
@KazChe
Copy link
Author

KazChe commented Mar 13, 2026

Hihi, sdk-ts-ci check failin due to a missing SPEAKEASY_API_KEY secret that'snot available to fork PRs and unrelated to the changes in this PR (python sdk only)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

control() decorator can break on streaming (async generator) functions for agents that have stream=true for latency.

2 participants